package com.rbac.modules.system.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rbac.common.api.R;
import com.rbac.modules.system.dto.LoginLogQuery;
import com.rbac.modules.system.entity.SysLoginLog;
import com.rbac.modules.system.service.SysLoginLogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Tag(name = "登录日志管理")
@RestController
@RequestMapping("/system/login-log")
@RequiredArgsConstructor
@Validated
public class SysLoginLogController {

    private final SysLoginLogService loginLogService;

    @Operation(summary = "分页查询登录日志")
    @SaCheckPermission(value = "system:login-log:list", orRole = "admin")
    @PostMapping("/page")
    public R<Page<SysLoginLog>> page(@RequestBody @Validated LoginLogQuery query) {
        return R.ok(loginLogService.page(query));
    }

    @Operation(summary = "清空登录日志")
    @SaCheckPermission(value = "system:login-log:clean", orRole = "admin")
    @DeleteMapping("/clean")
    public R<Void> clean() {
        loginLogService.clean();
        return R.ok();
    }
} 